package com.example.wwk.graduationpractice.Globalutils;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.Toast;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.example.wwk.graduationpractice.Globalutils.MyApplication;

/**
 * Created by wwk on 2017/3/20.
 * 弹出工具
 */

public class PromptShowUtils {
    public static void showSnackbar(View view, String msg) {
        Snackbar.make(view, msg, Snackbar.LENGTH_SHORT).show();
    }

    public static void showToast(String msg) {
        Toast.makeText(MyApplication.getContext(), msg, Toast.LENGTH_SHORT).show();
    }

    public static void showDialog(String title, String message, Context context) {
        new MaterialDialog.Builder(context)
                .title(title)
                .content(message)
                .positiveText("确定")
                .onAny(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (which == DialogAction.POSITIVE) {
                                ActivityCollector.finishAll();  //  关闭页面
                        }
                    }

                })
                .show();

    }
    public static void showDialog2(String title, String message, Context context) {
        new MaterialDialog.Builder(context)
                .title(title)
                .content(message)
                .positiveText("确定")
                .show();

    }
    public static void showDialog3(String title, String message, Context context) {
        new MaterialDialog.Builder(context)
                .title(title)
                .content(message)
                .positiveText("确定")
                .onAny(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (which == DialogAction.POSITIVE) {
                            ActivityCollector.getTopActivity().finish();  //  关闭当前页面
                        }
                    }

                })
                .show();

    }
}
